package com.adroiti.texasholdem.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.adroiti.texasholdem.Card;
import com.adroiti.texasholdem.Color;
import com.adroiti.texasholdem.engine.SimpleCard;

/**
 * CardMaker handles ...
 * <p>
 * $LastChangedDate$<br>
 * $LastChangedBy$<br>
 * $Revision$<br>
 * </p>
 */
public class CardMaker {
    /**
     * 
     * @param cardStr Takes string in format "C14:D2:S3"
     * @return
     */
    public static List<Card> getCardListFromString(String cardStr) {
        List<Card> cards = new ArrayList<Card>();
        Scanner scan = new Scanner(cardStr);
        if(cardStr.contains(" ")){
        	scan.useDelimiter(" ");
        }
        else scan.useDelimiter(":");
        String str = "";
        String color = "";
        Color col;
        int rank = 0;
        while (scan.hasNext()) {
            str = scan.next();
            color = str.substring(0, 1);
            rank = Integer.parseInt(str.substring(1));
            if(rank < 2 || rank > 14){
                throw new RuntimeException("Wrong card rank");
            }
            if (color.equals("H")) {
                col = Color.HEART;
            } else if (color.equals("C")) {
                col = Color.CLUB;
            } else if (color.equals("S")) {
                col = Color.SPADES;
            } else if (color.equals("D")){
                col = Color.DIAMOND;
            }
            else throw new RuntimeException("No such card type " + color);
            cards.add(new SimpleCard(col, rank));
        }
        return cards;
    }
}
